package com.shatower.chatctrl.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class RedisSource {

	private JedisPool jedisPool;


	/**
	 * 获取连接
	 * 
	 * @return
	 */
	public Jedis getConnection() {
		Jedis jedis = null;
		try {
			jedis = jedisPool.getResource();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jedis;
	}

	/**
	 * 关闭连接
	 * 
	 * @param jedis
	 */
	public void closeConnection(Jedis jedis) {
		if (null != jedis) {
			try {
				jedisPool.returnResource(jedis);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void destoryConnection(Jedis jedis) {
		if (null != jedis) {
			try {
				jedisPool.returnBrokenResource(jedis);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 设置连接池
	 * 
	 * @param JedisPool 数据源
	 *            .
	 */
	public void setJedisPool(JedisPool JedisPool) {
		this.jedisPool = JedisPool;
	}

	/**
	 * 获取连接池
	 * 
	 * @return 数据源
	 */
	public JedisPool getJedisPool() {
		return jedisPool;
	}

}
